<script type="text/javascript">
  $(function(){
    UM.getEditor('vip_desc', {
      textarea:'vip_desc',
      toolbar:[
        'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
        'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
        '| justifyleft justifycenter justifyright justifyjustify |',
        'link unlink',
        '| horizontal preview fullscreen'
      ]
    });
    UM.getEditor('zun_desc', {
      textarea:'zun_desc',
      toolbar:[
        'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
        'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
        '| justifyleft justifycenter justifyright justifyjustify |',
        'link unlink',
        '| horizontal preview fullscreen'
      ]
    });
    UM.getEditor('guwen_desc', {
      textarea:'guwen_desc',
      toolbar:[
        'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
        'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
        '| justifyleft justifycenter justifyright justifyjustify |',
        'link unlink',
        '| horizontal preview fullscreen'
      ]
    });
  });
  function createEncrypt(){
    var chars = random_chars(32);
    $("#encrypt_key").val(chars);
  }

</script>
<div class="bw-row pad10 cut">
  <form id="dataform" method="post" action="<{url m=$MOD c='setting' a='update' step='global'}>">
    <table class="dataform">
      <tr>
        <th width="180">系统名称</th>
        <td><input class="w250 txt" name="site_name" type="text" value="<{$rs.site_name}>" />
          <font class="caaa ml20">显示在小程序首页<img src="/public/image/peisong.png"></font>
        </td>
      </tr>
      <!--<tr>
        <th width="180">绑定管理员ID</th>
        <td><input class="w250 txt" name="openid" type="text" value="<{$rs.openid}>" /><font class="caaa ml20">绑定之后可以在小程序管理所有订单</font></td>
      </tr>-->

      <tr>
        <th width="180">VIP价格</th>
        <td>
          <input class="w50 txt" name="king_price" type="text" value="<{$vip_settings.king_price}>" placeholder="金卡VIP价格" /><font class="caaa ml20">金卡VIP价格</font><br><br>
          <input class="w50 txt" name="zun_price" type="text" value="<{$vip_settings.zun_price}>" placeholder="尊贵VIP价格" /><font class="caaa ml20">尊贵VIP价格</font><br><br>
        </td>
      </tr>
      <tr>
        <th width="180">顾问价格</th>
        <td>
          <input class="w50 txt" name="guwen_price" type="text" value="<{$vip_settings.guwen_price}>" placeholder="顾问价格" /><font class="caaa ml20">顾问价格</font><br><br>
        </td>
      </tr>

      <tr>
        <th width="180">总监奖励</th>
        <td>
          <input class="w50 txt" name="king_md" type="text" value="<{$vip_settings.king_md}>" placeholder="成为金卡VIP总监获得金额" /><font class="caaa ml20">成为金卡VIP总监获得金额</font><br><br>
          <input class="w50 txt" name="zun_md" type="text" value="<{$vip_settings.zun_md}>" placeholder="成为尊贵VIP总监获得金额" /><font class="caaa ml20">成为尊贵VIP总监获得金额</font><br><br>
        </td>
      </tr>

      <tr>
        <th width="180">总监伞下</th>
        <td>
          <input class="w50 txt" name="san_md" type="text" value="<{$vip_settings.san_md}>" placeholder="总监获得伞下服务奖百分比" />%<font class="caaa ml20">总监获得伞下服务奖百分比</font><br><br>
        </td>
      </tr>

      <tr>
        <th width="180">奖励天数</th>
        <td>
          <input class="w50 txt" name="king_day" type="text" value="<{$vip_settings.king_day}>" placeholder="金卡VIP返佣天数" /><font class="caaa ml20">金卡VIP返佣天数</font><br><br>
          <input class="w50 txt" name="zun_day" type="text" value="<{$vip_settings.zun_day}>" placeholder="尊贵VIP返佣天数" /><font class="caaa ml20">尊贵VIP返佣天数</font><br><br>
        </td>
      </tr>
      <tr>
        <th width="180">次数设置</th>
        <td>
          <input class="w50 txt" name="king_time" type="text" value="<{$vip_settings.king_time}>" placeholder="金卡VIP分享和服务返佣产品" /><font class="caaa ml20">金卡VIP分享和服务返佣产品</font><br><br>
          <input class="w50 txt" name="zun_time" type="text" value="<{$vip_settings.zun_time}>" placeholder="尊贵VIP分享和服务返佣产品" /><font class="caaa ml20">尊贵VIP分享和服务返佣产品</font><br><br>
        </td>
      </tr>
      <tr>
        <!--推荐别人购买VIP所得奖励-->
        <th width="180">直推奖</th>
        <td>
          <input class="w50 txt" name="king_zhitui" type="text" value="<{$vip_settings.king_zhitui}>" placeholder="金卡VIP一级返现金额" /><font class="caaa ml20">金卡VIP一级返现金额</font><br><br>
          <input class="w50 txt" name="zun_zhitui" type="text" value="<{$vip_settings.zun_zhitui}>" placeholder="尊贵VIP一级返现金额" /><font class="caaa ml20">尊贵VIP一级返现金额</font><br><br>
          <input class="w50 txt" name="king_zhitui2" type="text" value="<{$vip_settings.king_zhitui2}>" placeholder="金卡VIP二级返现金额" /><font class="caaa ml20">金卡VIP二级返现金额</font><br><br>
          <input class="w50 txt" name="zun_zhitui2" type="text" value="<{$vip_settings.zun_zhitui2}>" placeholder="尊贵VIP二级返现金额" /><font class="caaa ml20">尊贵VIP二级返现金额</font><br><br>
        </td>
      </tr>
      <!--每个人分享返佣得多少钱,自己所得-->
      <tr>
        <th width="180">分享返佣</th>
        <td>
          <input class="w50 txt" name="king_rake_back" type="text" value="<{$vip_settings.king_rake_back}>" placeholder="金卡VIP一级返现金额" /><font class="caaa ml20">金卡VIP一级返现金额</font><br><br>
          <input class="w50 txt" name="zun_rake_back" type="text" value="<{$vip_settings.zun_rake_back}>" placeholder="尊贵VIP一级返现金额" /><font class="caaa ml20">尊贵VIP一级返现金额</font><br><br>
          <!--<input class="w250 txt" name="king_time" type="text" value="" placeholder="金卡VIP赠送商品天数" /><br><br>
          <input class="w250 txt" name="zun_time" type="text" value="" placeholder="尊贵VIP赠送商品天数" /><br><br>-->
        </td>
      </tr>
      <!--购买产品-->
      <tr>
        <th width="180">服务返佣</th>
        <td>
          <input class="w50 txt" name="king_service_back" type="text" value="<{$vip_settings.king_service_back}>" placeholder="金卡VIP一级返现金额" /><font class="caaa ml20">金卡VIP一级返现金额</font><br><br>
          <input class="w50 txt" name="zun_service_back" type="text" value="<{$vip_settings.zun_service_back}>" placeholder="尊贵VIP一级返现金额" /><font class="caaa ml20">尊贵VIP一级返现金额</font><br><br>
          <input class="w50 txt" name="king_service_back2" type="text" value="<{$vip_settings.king_service_back2}>" placeholder="金卡VIP二级返现金额" /><font class="caaa ml20">金卡VIP二级返现金额</font><br><br>
          <input class="w50 txt" name="zun_service_back2" type="text" value="<{$vip_settings.zun_service_back2}>" placeholder="尊贵VIP二级返现金额" /><font class="caaa ml20">尊贵VIP二级返现金额</font><br><br>
          <!--<input class="w250 txt" name="king_time" type="text" value="" placeholder="金卡VIP赠送商品天数" /><br><br>
          <input class="w250 txt" name="zun_time" type="text" value="" placeholder="尊贵VIP赠送商品天数" /><br><br>-->
        </td>
      </tr>
      <tr>
        <th width="180">金卡VIP购买说明</th>
        <td>
          <script type="text/plain" id="vip_desc" style="width:100%;height:200px;"><{$vip_settings.vip_desc nofilter}></script>
        </td>
      </tr>
      <tr>
        <th width="180">尊贵VIP购买说明</th>
        <td>
          <script type="text/plain" id="zun_desc" style="width:100%;height:200px;"><{$vip_settings.zun_desc nofilter}></script>
        </td>
      </tr>
      <tr>
        <th width="180">专家顾问说明</th>
        <td>
          <script type="text/plain" id="guwen_desc" style="width:100%;height:200px;"><{$vip_settings.guwen_desc nofilter}></script>
        </td>
      </tr>
      <!--<tr>
        <th>服务描述</th>
        <td>
          <input class="w100 txt" name="miaoshu[]" type="text" value="<{$rs.miaoshu.0}>" onkeyup="calculate(this)" />
          <input class="w100 txt" name="miaoshu[]" type="text" onkeyup="calculate(this)" value="<{$rs.miaoshu.1}>" />
          <input class="w100 txt" name="miaoshu[]" type="text" onkeyup="calculate(this)" value="<{$rs.miaoshu.2}>" />
          <font class="caaa ml20">最多5个汉字，显示在小程序首页<img src="/public/image/fuwumiaoshu.png"></font>
        </td>
        <script language="javascript">
          function calculate(obj){
            var val = obj.value;
            havecount =val.replace(/[\u4E00-\u6FA5]/g,"**").length
            if(havecount > 10){
              alert('最多只能输入5个汉字，10个英文字母');
              var chao = havecount - 10;
              obj.value = val.substr(0, (havecount - chao) / 2);
              return false;
            }
          }
        </script>
      </tr>
      <tr>
        <th>打印机设置</th>
        <td>
          <div class="pad5">
            <label><input class="w150 txt" type="text" name="printer[]" value="<{$rs.printer.0}>" placeholder="输入机器号"></label>
            <label><input class="w150 txt" type="text" name="printer[]" value="<{$rs.printer.1}>" placeholder="输入秘钥"></label>
            <font class="ml20 vtcmid caaa">支持365打印机</font>
          </div>
        </td>
      </tr>
      <tr>
        <th>配送半径</th>
        <td>
          <div class="pad5">
            <label><input type="radio" name="visitor_stats" value="1" <{if $rs.visitor_stats == 1}>checked="checked"<{/if}> /><font class="green ml5">开启</font></label>
            <label class="ml20"><input type="radio" name="visitor_stats" value="0" <{if $rs.visitor_stats == 0}>checked="checked"<{/if}> /><font class="red ml5">关闭</font></label>
            <font class="ml20 vtcmid caaa">开启访问量统计，系统将会自动统计网站访问量，此举将会增加服务器资源消耗，如空间用户或访问量过大时建议使用第三方统计代码</font>
          </div>
        </td>
      </tr>
      <tr>
        <th>多IP同时登录管理员账号</th>
        <td>
          <div class="pad5">
            <label><input type="radio" name="admin_mult_ip_login" value="1" <{if $rs.admin_mult_ip_login == 1}>checked="checked"<{/if}> /><font class="green ml5">允许</font></label>
            <label class="ml20"><input type="radio" name="admin_mult_ip_login" value="0" <{if $rs.admin_mult_ip_login == 0}>checked="checked"<{/if}> /><font class="red ml5">不允许</font></label>
            <font class="ml20 vtcmid caaa">是否允许多IP同时登陆相同管理员账号，如不允许，系统将在用户登录时检测该账号是否已经被其他IP登录并给出提示</font>
          </div>
        </td>
      </tr>-->
      <{if isset($business['business'])}>
      <tr>
        <th>经营范围</th>
        <td>
          <select class="slt" id="business" disabled>
            <option value="0">请选择</option>
            <option value="1" <{if $business['business'] == 1}>selected<{/if}>>本地生活服务</option>
            <option value="2" <{if $business['business'] == 2}>selected<{/if}>>全国商品销售</option>
          </select>
          <font class="caaa ml20">一旦保存无法修改，请谨慎选择</font>
        </td>
      </tr>
      <{if $business['business'] == 1}>
      <tr>
        <th>配送范围</th>
        <td>
          <div style="margin: 0 0 5px 0;">
            <input id="xianding" class="w150 txt" placeholder="限定11范围，单位公里,默认5公里" type="number" name="xianding" value="<{if isset($business['xianding'])}><{$business['xianding']}><{else}>0<{/if}>">
          </div>
          <div style="width:900px;height:900px" id="container"></div>
        </td>
        <input type="hidden" name="business" value="1">
        <input type="hidden" name="points" id="points" value="<{if strlen($rs.points) > 10}><{$rs.points}><{/if}>">
      </tr>
      <{/if}>
      <{if $business['business'] == 2}>
      <tr>
        <th>条件免邮</th>

        <{if isset($business['mianyou'])}>
        <td>
          <input type="hidden" name="business" value="2">
          <p><font>消费满 <input class="w150 txt" type="number" name="mianyou" id="mianyou" min="1" max="888" value="<{$business['mianyou']}>"> 免邮/配送</font></p><br>
          <p><font>配送费 <input class="w150 txt" type="number" name="peisongfei" id="peisongfei" min="1" max="888" value="<{$business['peisongfei']}>"></font></p>
        </td>
        <{else}>
        <td>
          <input type="hidden" name="business" value="2">
          <p><font>消费满 <input class="w150 txt" type="number" name="mianyou" id="mianyou" min="1" max="888" value=""> 免邮/配送</font></p><br>
          <p><font>配送费 <input class="w150 txt" type="number" name="peisongfei" id="peisongfei" min="1" max="888" value=""></font></p>
        </td>
        <{/if}>
      </tr>
      <{/if}>
      <{else}>
      <tr>
        <th>经营范围</th>
        <td>
          <select class="slt" name="business" id="business" onchange="show_settings(this.options[this.selectedIndex].value)">
            <option value="0">请选择</option>
            <option value="1">本地生活服务</option>
            <option value="2">全国商品销售</option>
          </select>
          <font class="caaa ml20">一旦保存无法修改，请谨慎选择</font>
        </td>
      </tr>
      <tr id="b1" class="hide">
        <th>配送范围</th>
        <td>
          <div>
            <input class="w150 txt" placeholder="限定22范围，单位公里,默认5公里" type="number" name="xianding" value="" id="xianding">
          </div>
          <div style="width:900px;height:900px" id="container"></div>
        </td>
        <input type="hidden" name="points" id="points" value="<{if strlen($rs.points) > 10}><{$rs.points}><{/if}>">
      </tr>
      <tr id="b2" class="hide">
        <th>条件免邮</th>
        <td>
          <p><font>消费满 <input class="w150 txt" type="number" name="mianyou" id="mianyou" min="1" max="888"> 免邮/配送</font></p><br>
          <p><font>配送费 <input class="w150 txt" type="number" name="peisongfei" id="peisongfei" min="1" max="888"></font></p>
        </td>
      </tr>
      <{/if}>
      <!--<tr>
        <th>网站底部信息</th>
        <td><script type="text/plain" id="footer_info" style="width:100%;height:200px;"><{$rs.footer_info nofilter}></script></td>
      </tr>-->
    </table>
    <div class="submitbtn" style="padding-left:260px;">
      <button type="button" class="ubtn btn">保存并更新全局设置</button>
      <button type="reset" class="fbtn btn">重置表单</button>
    </div>
  </form>
</div>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&libraries=drawing"></script>
<script>
  $('.ubtn').click(function(){
    var business = $("#business").val();
    if(typeof business === 'undefined' || business == 0){
      alert('请选择经营范围');
      return;
    }
    if(business == 1){
      var xianding = $("#xianding").val();
      if(typeof xianding === 'undefined' || xianding < 1){
        alert('请填写配送限定范围');
        return;
      }
    }else if(business == 2){
      var mianyou = $("#mianyou").val();
      var peisongfei = $("#peisongfei").val();
      if(mianyou.length < 1 || peisongfei.length < 1){
        alert('请填写免邮金额，配送费');
        return;
      }
    }else{
      alert('系统错误');
      return;
    }
    var form = document.getElementById('dataform');
    form.submit();
  });
  var dtype = 0

  function show_settings(id){
    if(id == 1){
      dtype = 1;
      var hide = 2;
    }else{
      dtype = 2;
      var hide = 1;
    }
    $('#b' + dtype).show();
    $('#b' + hide).hide();
  }

  var xianding = $("#xianding").val();
  if(typeof xianding === 'undefined' || xianding < 1){
    var radius = 5000;
    $("#xianding").val(5);
  }else{
    var radius = parseInt(xianding) * 1000;
  }

  var overlaysArray = []; //覆盖物容器,用于清除覆盖物
  var points = "";
  var map;

  <{if strlen($rs.points) > 10}>

  init(radius);
  function init(radius) {
    var center = new qq.maps.LatLng(<{$rs.points}>);
    map = new qq.maps.Map(document.getElementById("container"), {
      center : center,
      zoom : 12
    });
    var circle = new qq.maps.Circle({
      map: map,
      center: center,
      //radius: 5000,
      radius:radius,
      strokeWeight: 5
    });
    circle.setVisible(true);
    if (circle.getMap()) {
      circle.setMap(null);
    } else {
      circle.setMap(map);
    }circle.setMap(map);

  }
  <{else}>
  map = new qq.maps.Map(document.getElementById("container"), {
    center : new qq.maps.LatLng(22.551879,114.046326),
    zoom : 12
  });
  <{/if}>





  var drawingManager = new qq.maps.drawing.DrawingManager({
    drawingMode: qq.maps.drawing.OverlayType.MARKER,
    //drawingMode: qq.maps.drawing.OverlayType.POLYGON,
    drawingControl: true,
    drawingControlOptions: {
      position: qq.maps.ControlPosition.TOP_CENTER,
      drawingModes: [
        qq.maps.drawing.OverlayType.MARKER,
        //qq.maps.drawing.OverlayType.CIRCLE,
        //qq.maps.drawing.OverlayType.POLYGON,
        //qq.maps.drawing.OverlayType.RECTANGLE
      ]
    },

    markerOptions:{
      visible:false
    },
    circleOptions: {
      fillColor: new qq.maps.Color(255, 208, 70, 0.3),
      strokeColor: new qq.maps.Color(88, 88, 88, 1),
      strokeWeight: 5,
      clickable: false
    }
  });
  drawingManager.setMap(map);


  qq.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
    if(event.type=="marker"){
      clearOverlays(overlaysArray);

      var latLng =event.overlay.getPosition();
      lat = latLng.getLat().toFixed(5);
      lng = latLng.getLng().toFixed(5);
      var center = new qq.maps.LatLng(lat, lng);
      var geocoder = new qq.maps.Geocoder();
      geocoder.getAddress(latLng);
//设置服务请求成功的回调函数
      geocoder.setComplete(function(result) {
        doMarker(center, result.detail.address + latLng);
        doCircle(center);
        //getPeopleDataByCircle(radius,lat+","+lng);
        $("#points").val(lat+','+lng);

      });
//若服务请求失败，则运行以下函数
      geocoder.setError(function() {
        alert("出错了，请输入正确的经纬度！！！");
      });

    }else if(event.type=="circle"){
      clearOverlays(overlaysArray);
      overlaysArray.push(event.overlay);
      var latLng =event.overlay.getCenter();
      var newRadius=event.overlay.getRadius();
      lat = latLng.getLat().toFixed(5);
      lng = latLng.getLng().toFixed(5);
      var center = new qq.maps.LatLng(lat, lng);
      var geocoder = new qq.maps.Geocoder();
      geocoder.getAddress(latLng);
//设置服务请求成功的回调函数
      geocoder.setComplete(function(result) {
        doMarker(center, result.detail.address + latLng);
        getPeopleDataByCircle(newRadius,lat+","+lng);

      });
//若服务请求失败，则运行以下函数
      geocoder.setError(function() {
        alert("出错了，请输入正确的经纬度！！！");
      });

    }else if(event.type=="polygon"||event.type=="rectangle"){
      clearOverlays(overlaysArray);
      overlaysArray.push(event.overlay);

      event.overlay.getPath().forEach(function(e){
        var lng=e.getLng();
        var lat=e.getLat();
        points+=lng+" "+lat+",";
      });
      points=points.substring(0, points.length-1);
      getPeopleDataByPolygon(points);

      //console.log(latlngBounds.contains(new qq.maps.LatLng(29.936273,116.440043)));
    }
  });

  //清除覆盖物
  function clearOverlays(overlaysArray) {
    if (overlaysArray) {
      for (i in overlaysArray) {
        overlaysArray[i].setMap(null);
      }
    }
  }

  //画圆中心点
  function doMarker(center, title) {
//创建一个Marker
    var marker = new qq.maps.Marker({
//设置Marker的位置坐标
      position : center,
//设置显示Marker的地图
      map : map,
      title : title
    });


//设置Marker的可见性，为true时可见,false时不可见，默认属性为true
    marker.setVisible(true);
//设置Marker的动画属性为从落下
    marker.setAnimation(qq.maps.MarkerAnimation.DOWN);
    overlaysArray.push(marker);
    marker.setMap(map);
  }

  //画圆
  function doCircle(center) {
    var circle = new qq.maps.Circle({
      map : map,
      center : center,
      radius : radius,
      strokeWeight : 5
    });
    overlaysArray.push(circle);
    circle.setMap(map);
  }


  //查询圆数据
  function getPeopleDataByCircle(radius,center) {
//var circlePath="<%=basePath%>searchProjectInfo?op=circle&raidus="
//+ radius + "&point=" + center;
//jQuery.getJSON(circlePath, function(data) {
//showPeopleData(data);
//});
    //alert("圆形中心为:"+center+"半径为:"+radius);
    //console.log(center + ' - ' + radius);
  }

  //查询多边形数据
  function getPeopleDataByPolygon(points) {
//var polygonPath="<%=basePath%>searchProjectInfo?op=polygon&points="
//+ points;
//jQuery.getJSON(polygonPath, function(data) {
//showPeopleData(data);
//});

    //alert("多边形路径为:"+points);
    //114.00203704833984 22.66787787222139,113.97148132324219 22.636510836241445,114.06246185302734 22.620983087268936,114.06349182128906 22.643798766430393
    //console.log(points);
    $("#points").val(points);

  }


</script>
<script type="text/javascript" src="public/theme/backend/umeditor/umeditor.config.js"></script>
<script type="text/javascript" src="public/theme/backend/umeditor/umeditor.min.js"></script>